package cn.itcast.bos.web.action;


import java.util.HashMap;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.TransitInfoService;
import cn.itcast.bos.web.action.common.BaseAction;

@ParentPackage(value="json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class TransitInfoAction extends BaseAction<TransitInfo> {

	@Autowired
	private TransitInfoService transitInfoService;
	
	//属性驱动,接受运单wayBillIds
	private String  wayBillIds;

	public void setWayBillIds(String wayBillIds) {
		this.wayBillIds = wayBillIds;
	}
	@Action(value = "transit_create", results = { @Result(name = "success", type = "json") })
	public String create() {
		// 调用业务层， 保存transitInfo信息
		HashMap<String,Object> hashMap = new HashMap<String ,Object>();
		
		try {
			transitInfoService.createTransits(wayBillIds);
			//成功
			hashMap.put("success", true);
			hashMap.put("msg", "开启中转配送成功!");
		} catch (Exception e) {
			e.printStackTrace();
			//失败
			hashMap.put("success", false);
			hashMap.put("msg", "开启中转配送失败，异常："+e.getMessage());
		}
		ActionContext.getContext().getValueStack().push(hashMap);
		
		return SUCCESS;
	}
	
	/**
	 * 出入库中运单信息的回显
	 */
	@Action(value = "transit_pageQuery", results = { @Result(name = "success", type = "json") })
	public String pageQuery() {
		//分页查询
		Pageable pageable =new PageRequest(page-1, rows);
		//调用业务层,查询分页数据
		Page<TransitInfo> pageData=transitInfoService.findPageData(pageable);
		//压栈
		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}
	
	
	
}













